#include <string.h>
#include <math.h>
#include <iostream>
using std::cout;
using std::endl;

class Point{
public:
    Point(float x, float y)
    :_x(x)
    ,_y(y)
    {

    }
    friend class Line;

private:
    float _x;
    float _y;
};

class Color{
public:
    Color(const char * color)
    :_color(new char[strlen(color) + 1]())
    {
        strcpy(_color, color);
    }
    //第一个const标识的是const char *
    //第二个const标识的是const成员函数
    const char * getColor() const {
        return _color;
    }

private:
    char * _color;
};

class Line{
public:
    Line(float x1, float y1, float x2, float y2)
    :_pt1(x1, y1)
    ,_pt2(x2, y2)
    {

    }

    //勾股定理
    //作为底
    float distance(){
        float x = pow(_pt1._x - _pt2._x, 2);
        float y = pow(_pt1._y - _pt2._y, 2);
        return sqrt(x + y);
    }

private:
    Point _pt1;
    Point _pt2;
};

class Triangle : public Line, public Color {
public:
    Triangle(float x1, float y1, float x2, float y2, float height, const char * color)   
    :Line(x1, y1, x2, y2)
    ,Color(color)
    ,_height(height)
    {
        
    }


    //直角三角形:a + b + sqrt(a^2 + b ^2);
    float getPerimeter(){
        float c = sqrt(pow(distance(), 2) + pow(_height, 2));
        return distance() + _height + c;
    }

    float getArea(){
        return distance() * _height / 2;
    }
    
private:
    float _height;
    
};



void test(){
    Triangle tri(0, 0, 3, 0, 4, "blue");
    cout << tri.getArea() << endl;
    cout << tri.getPerimeter() << endl;
    cout << tri.getColor() << endl;
}

int main()
{
    test();
    return 0;
}

